package cn.school.controller.workflow;


import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.common.exception.ApiException;
import cn.school.workflow.service.MeetingReservedApplyService;
import cn.school.workflow.vo.MeetingReservedApplyVO;
import cn.school.workflow.vo.WorkFlowVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/meetingApply")
@Api(tags = "会议预定接口")
public class MeetingReservedApplyController {

    @Resource
    private MeetingReservedApplyService meetingReservedApplyService;

    /**
     * 查询公文信息
     * @return
     * @throws ApiException
     */
    @PostMapping("/findMeetingApplyPageList")
    @ApiOperation("list => 分页查询会议室预定申请单")
    public CommonResult<CommonPage<MeetingReservedApplyVO>> findMeetingApplyPageList(@RequestBody MeetingReservedApplyVO vo) throws ApiException{
        IPage<MeetingReservedApplyVO> pageList =  meetingReservedApplyService.findMeetingApplyPageList(vo);
        return  CommonResult.success(CommonPage.restPage(pageList));
    }

    @PostMapping("/cancelMeetingApply")
    @ApiOperation("cancel => 撤销会议预定申请")
    public CommonResult<Integer> cancelMeetingApply(@RequestBody WorkFlowVO vo) throws ApiException{
        boolean flag =  meetingReservedApplyService.cancelMeetingApply(vo);
        if(flag){
            return CommonResult.success();
        }
        return  CommonResult.failed("流程取消失败");
    }

    @PostMapping("/createMeetingApply")
    @ApiOperation("create => 创建会议预定流程")
    public CommonResult<Integer> createMeetingApply(@RequestBody MeetingReservedApplyVO  vo) throws ApiException{
        int flag =  meetingReservedApplyService.createMeetingApply(vo);
        if(flag>0){
            return CommonResult.success();
        }
        return  CommonResult.failed("流程创建失败");
    }

    @GetMapping("/findMeetingApplyDetail/{processInstanceId}")
    @ApiOperation("detail => 会议预定详情")
    public CommonResult<MeetingReservedApplyVO> findMeetingApplyDetail(@PathVariable("processInstanceId") Long processInstanceId) throws ApiException{
        MeetingReservedApplyVO meetingReservedApplyVO =  meetingReservedApplyService.findMeetingApplyDetail(processInstanceId);
        if(meetingReservedApplyVO!=null){
            return CommonResult.success(meetingReservedApplyVO);
        }
        return  CommonResult.failed("查询不单申请单");
    }
}
